package 面试;

public class 查询字符串出现的次数 {
    public static void main(String[] args) {
        String str = "adgsdgadsdfadsdad";
        String ts = "adsf";
        int count = 0;
        if(!str.contains(ts)){
            System.out.println(count);
            return;
        }
        int index = 0;
        while ((index = str.indexOf(ts))!=-1){
            str = str.substring(index+ts.length());
            count++;
        }
        System.out.println(count);
    }
}
